package com.example.kotlin

fun main(args: Array<String>) {

    val numbers = listOf(1, 2, 3)
    val doubled = numbers.map { it * 2 } // 输出: [2, 4, 6]
    println(doubled)
    println("---------------------------------------分割线-------------------------------------")

    val evenNumbers = numbers.filter { it % 2 == 0 } // 输出: []
    println(evenNumbers)
    println("---------------------------------------分割线-------------------------------------")

    val sum = numbers.reduce { acc, i -> acc + i } // 输出: 6
    println(sum)
    println("---------------------------------------分割线-------------------------------------")

    val sumWithInitial = numbers.fold(10) { acc, i -> acc + i } // 输出: 16
    println(sumWithInitial)
    println("---------------------------------------分割线-------------------------------------")

    numbers.forEach { println(it) }
    println("---------------------------------------分割线-------------------------------------")

    val firstEven = numbers.find { it % 2 == 0 } // 输出: null
    println(firstEven)
    println("---------------------------------------分割线-------------------------------------")

    val hasEven = numbers.any { it % 2 == 0 } // 输出: false
    val allPositive = numbers.all { it > 0 } // 输出: true
    println(hasEven)
    println(allPositive)
    println("---------------------------------------分割线-------------------------------------")

    val countOfEvens = numbers.count { it % 2 == 0 } // 输出: 0
    println(countOfEvens)
    println("---------------------------------------分割线-------------------------------------")

    val grouped = numbers.groupBy { it % 2 } // 输出: {1=[1], 0=[2, 3]}
    println(grouped)
    println("---------------------------------------分割线-------------------------------------")

    val letters = listOf("A", "B", "C")
    val zipped = numbers.zip(letters) // 输出: [(1, A), (2, B), (3, C)]
    println(zipped)

}